
setwd()

## Load packages
library(tidyverse) 
library(sjmisc) 
library(forcats)
library(parameters)
library(ggeffects)
library (marginaleffects)


### Load data 
load()

# Start of the script
#########################################
# Data management---------------------------------------------------------------
# Dependent variable -> Vote Change --------------------------------------------

## Recode vote intention pre and post treatment (collapse categories favor/against)

df <- df %>% mutate(across(c(exp_vint, vint_prop27_w1),
                           ~fct_collapse(., 
                                         favor = c("certainly favor","likely favor"),
                                         against = c("certainly against","likely against"),
                                         dk = c("dk")),
                           .names = "rcd_{col}"))

## Vote intention pre-treatment : binary w/o "dk"
df <- df %>% mutate(vint_prop27_w1_bin = case_when(rcd_vint_prop27_w1 == "dk" ~ NA,
                                                   TRUE ~ rcd_vint_prop27_w1)) %>% droplevels()

## Vote intention post-treatment : binary w/o "dk"
df <- df %>% mutate(exp_vint_bin = case_when(rcd_exp_vint == "dk" ~ NA,
                                             TRUE ~ rcd_exp_vint)) %>% droplevels()

## Mutate vote change (all possible changes pre and post treatment)
xtabs(~ rcd_exp_vint + rcd_vint_prop27_w1, data = df, subset = NULL)

df <- df %>% mutate(vote_prepost = case_when(rcd_vint_prop27_w1 == "favor" & rcd_exp_vint == "favor" ~ "favor -> favor",
                                             rcd_vint_prop27_w1 == "against" & rcd_exp_vint == "against" ~ "against -> against",
                                             rcd_vint_prop27_w1 == "dk" & rcd_exp_vint == "dk" ~ "dk -> dk",
                                             rcd_vint_prop27_w1 == "favor" & rcd_exp_vint == "against" ~ "favor -> against",
                                             rcd_vint_prop27_w1 == "favor" & rcd_exp_vint == "dk" ~ "favor -> dk",
                                             rcd_vint_prop27_w1 == "against" & rcd_exp_vint == "favor" ~ "against -> favor",
                                             rcd_vint_prop27_w1 == "against" & rcd_exp_vint == "dk" ~ "against -> dk",
                                             rcd_vint_prop27_w1 == "dk" & rcd_exp_vint == "favor" ~ "dk -> favor",
                                             rcd_vint_prop27_w1 == "dk" &rcd_exp_vint == "against" ~ "dk -> against"))

# We remove respondents who remain undecided and who is susceptible to activation and demobilization

# undecided voters all along. N = 190 
df <- df %>%  filter(
  !((vote_prepost == "dk -> dk")))

# activation and demobilization. N = 377
df <- df %>%  filter(
  !((vote_prepost == "against -> dk"  | 
       vote_prepost == "favor -> dk"  | 
       vote_prepost == "dk -> against"  | 
       vote_prepost == "dk -> favor")))

## Recode vote change (2 categories)
df$vote_prepost_rcd_bin <- fct_collapse(df$vote_prepost, stability = c("against -> against", "favor -> favor"),
                                        change = c("against -> favor", "favor -> against"))

## Experimental groups ----------------------------------------------------------
# Create groups based on conflicting and affirming cues and arguments

## Party recommendation (nothing, YES, NO)
df <- df %>% mutate(exp_party_reco_rcd = case_when(exp_grp == "no arg, no cue" | exp_grp == "arg pro, no cue" |
                                                     exp_grp == "arg contra, no cue" | exp_grp == "arg mixed, no cue" ~ "nothing",
                                                   TRUE ~ as.character(exp_party_reco)))
## Variable for each type of argument 
df <- df %>%
  mutate(exp_arg = case_when(
    grepl("pro", exp_grp, ignore.case = TRUE) ~ "pro",
    grepl("contra", exp_grp, ignore.case = TRUE) ~ "contra",
    grepl("mixed", exp_grp, ignore.case = TRUE) ~ "mixed",
    grepl("no arg", exp_grp, ignore.case = TRUE) ~ "no arg",
    TRUE ~ NA_character_))

## Variable - affirming or conflicting cue (party recommendation x pre vote intention) (H1;H2)
df <- df %>% 
  mutate(aff_conf_cue = case_when(
    vint_prop27_w1_bin == "favor" & exp_party_reco_rcd == "no" ~ "conflicting cue",
    vint_prop27_w1_bin == "favor" & exp_party_reco_rcd == "nothing" ~ "nothing",
    vint_prop27_w1_bin == "favor" & exp_party_reco_rcd == "yes" ~ "affirming cue",
    vint_prop27_w1_bin == "against" & exp_party_reco_rcd == "no" ~ "affirming cue",
    vint_prop27_w1_bin == "against" & exp_party_reco_rcd == "nothing" ~ "nothing",
    vint_prop27_w1_bin == "against" & exp_party_reco_rcd == "yes" ~ "conflicting cue",
    TRUE ~ NA))


## Factor Variable - affirming or conflicting argument (arguments x pre vote intention) (H1;H2)
df <- df %>% 
  mutate(aff_conf_arg = case_when(
    vint_prop27_w1_bin == "favor" & exp_arg == "contra" ~ "conflicting arg",
    vint_prop27_w1_bin == "favor" & exp_arg == "mixed" ~ "balanced arg",
    vint_prop27_w1_bin == "favor" & exp_arg == "no arg" ~ "no arg",
    vint_prop27_w1_bin == "favor" & exp_arg == "pro" ~ "affirming arg",
    vint_prop27_w1_bin == "against" & exp_arg == "contra" ~ "affirming arg",
    vint_prop27_w1_bin == "against" & exp_arg == "mixed" ~ "balanced arg",
    vint_prop27_w1_bin == "against" & exp_arg == "no arg" ~ "no arg",
    vint_prop27_w1_bin == "against" & exp_arg == "pro" ~ "conflicting arg",
    TRUE ~ NA))

# We Remove respondents that cannot be identified as republicans or democrats. 
# Here the N missing is 602 which corresponds to respondents not identifying to any party and having declared dk on the lcscale (188) + those that did not provide a preferred party and placed themselves on lcscale 5 (414)
df<- df %>%  filter(
  !((lcscale_w1 == 99 & (pid_first_w1 %in% c("dk", "Other"))) |
      (lcscale_w1 == 99 & (pid_remind_first_w1 %in% c("dk", "Other"))) |
      (lcscale_w1 == 99 & (is.na(pid_first_w1) & is.na(pid_remind_first_w1)))))
df <- df %>%  filter(
  !((lcscale_w1 == 5 & (pid_first_w1 %in% c("dk", "Other"))) |
      (lcscale_w1 == 5 & (pid_remind_first_w1 %in% c("dk", "Other"))) |
      (lcscale_w1 == 5 & (is.na(pid_first_w1) & is.na(pid_remind_first_w1)))))

### Moderators -------------------------------------------------------------------

# Moderator n1. - Partisanship (H3)
## We derive partisanship from the battery of questions in Appendix B
df <- df %>% mutate(party_strength= case_when(
  pid_close_w1 == "yes" & pid_first_w1 %in% c("Democrat", "Republican") & pid_strength_w1 == "Very close" ~ "2",
  pid_close_w1 == "yes" & pid_first_w1 %in% c("Democrat", "Republican") & pid_strength_w1 == "Not very close" ~ "1",
  TRUE ~ "0"
))

df$party_strength <- as.factor(df$party_strength)
df$party_strength_bin <- fct_collapse(df$party_strength, weak_partisan = c("0"),
                                      strong_partisan = c("1", "2"))

# Moderator n2 - Sophistication (H4) �
## Sophistication scale based on issue specific knowledge and interest in politics

## Create issue specific knowledge scale

df <- df %>% mutate(isknow_prop27_c = case_when(
  isknow_prop27_c_w1 == "companies (correct)" ~ 1,
  isknow_prop27_c_w1 %in% c("cali companies only", "cardrooms", "cities", "dk") ~ 0,
  TRUE ~ NA_integer_ ))
df <- df %>% mutate(isknow_prop27_d = case_when(
  isknow_prop27_d_w1 == "homelessness and dev of Tribes (correct)" ~ 1,
  isknow_prop27_d_w1 %in% c("future pandemics", "homelessness", "general fund", "dk") ~ 0,
  TRUE ~ NA_integer_))

df <- df %>% mutate(is_know_prop27_scale = isknow_prop27_c + isknow_prop27_d)

## Recode Political Interest into numerical scale
df <- df %>%
  mutate(polint = case_when(
    polint_w1 == "not at all" ~ 0,
    polint_w1 == "not very" ~ 1,
    polint_w1 == "somewhat" ~ 2,
    polint_w1 == "very" ~ 3
  ))

## Create sophistication scale
df <- df %>% mutate(soph_scale = df$polint + is_know_prop27_scale)
soph_scale <- df$soph_scale
df <- df %>%  mutate( soph_category = ifelse(soph_scale <= mean(soph_scale), "low soph", "high soph"))
rm(soph_scale)

# Moderator n3 - Attitude strength (H5)

df <- df %>% mutate(attitudes = factor(vint_prop27_w1, 
                                       levels = c("certainly favor", 
                                                  "likely favor", 
                                                  "likely against", 
                                                  "certainly against"), 
                                       labels = c("strong", "weak", "weak", "strong")))

########################################
### Regression analyses - Logit models -----------------------------------------

# prepare reference categories variables of interest 
df$aff_conf_arg <- as.factor(df$aff_conf_arg)
df$aff_conf_arg <- relevel(df$aff_conf_arg, ref = "no arg")

df$aff_conf_cue <- as.factor(df$aff_conf_cue)
df$aff_conf_cue <- relevel(df$aff_conf_cue, ref = "nothing")

# Logit model (1) Appendix E1 -> Main effect 
m <- glm(vote_prepost_rcd_bin ~ aff_conf_arg + aff_conf_cue, data = df, family = binomial(link = "logit"))
summary(m)

# Logit model (2) Appendix E1 -> Interaction effect between cues and arguments 
mx <- glm(vote_prepost_rcd_bin ~ aff_conf_arg * aff_conf_cue, data = df, family = binomial(link = "logit"))
summary(mx)

# Logit model (3) Appendix E1 -> Interaction effect between cues, arguments and partisanship
mp <- glm(vote_prepost_rcd_bin ~ aff_conf_arg*aff_conf_cue*party_strength_bin, data = df, family = binomial(link = "logit"))
summary(mp)

# Logit model (4) Appendix E1 -> Interaction effect between cues, arguments and sophistication
msoph <- glm(vote_prepost_rcd_bin ~ aff_conf_arg*aff_conf_cue*soph_category, data = df, family = binomial(link = "logit"))
summary(msoph)

# Logit model (5) Appendix E1 -> Interaction effect between cues, arguments and attitude strength
mxs <- glm(vote_prepost_rcd_bin ~ aff_conf_arg * aff_conf_cue* attitudes, data = df, family = binomial(link = "logit"))
summary(mxs)

########################################
#### Difference in probabilities Fig.1------------------------------------------------

# Difference in probabilities separate effects of policy information and party cues 
# In hypothesis b2 and b4 are the reference categories (no arg nothing)

# Conflicting cue
conflicting_cue <- predictions(m, newdata = datagrid(aff_conf_arg = c("no arg","no arg"),
                                                     aff_conf_cue = c("conflicting cue","nothing")),type= "response")

conflicting_cue <- hypotheses(conflicting_cue, hypothesis = "b1 = b2", type= "response")
conflicting_cue$term <- "Conflicting cue and no arguments"

# Conflicting argument 
conflicting_arg <- predictions(m, newdata = datagrid(aff_conf_arg = c("conflicting arg","no arg"),
                                                     aff_conf_cue = c("nothing","nothing")),type= "response")

conflicting_arg <- hypotheses(conflicting_arg, hypothesis = "b1 = b2", type= "response")
conflicting_arg$term <- "Conflicting arguments and no cue"

# Conflicting argument conflicting cue 
conflicting_arg_cue <- predictions(mx, newdata = datagrid(aff_conf_arg = c("conflicting arg","no arg"),
                                                          aff_conf_cue = c("conflicting cue","nothing")),type= "response")

conflicting_arg_cue<- hypotheses(conflicting_arg_cue, hypothesis = "b1 = b4", type= "response")
conflicting_arg_cue$term <- "Conflicting arguments and conflicting cue"

# Difference in probabilities H1a
h1a <- predictions(mx, newdata = datagrid(aff_conf_arg = c("affirming arg","no arg"),
                                          aff_conf_cue = c("conflicting cue","nothing")),type= "response")
h1a <- hypotheses(h1a, hypothesis = "b1 = b4", type= "response")
h1a$term <- "H1a - confirming arguments and conflicting cue"

# Difference in probabilities H1b
h1b <- predictions(mx, newdata = datagrid(aff_conf_arg = c("conflicting arg","no arg"),
                                         aff_conf_cue = c("affirming cue","nothing")),type= "response")
h1b <- hypotheses(h1b, hypothesis = "b1 = b4", type= "response")
h1b$term <- "H1b - conflicting arguments and confirming cue"

# Difference in probabilities H2b
h2a <- predictions(mx, newdata = datagrid(aff_conf_arg = c("balanced arg","no arg"),
                                          aff_conf_cue = c("conflicting cue","nothing")),type= "response")
h2a <- hypotheses(h2a, hypothesis = "b1 = b4", type= "response")
h2a$term <- "H2a - balanced arguments and conflicting cue"

#  Difference in probabilities H2b
h2b <- predictions(mx, newdata = datagrid(aff_conf_arg = c("balanced arg","no arg"),
                                          aff_conf_cue = c("affirming cue","nothing")),type= "response")
h2b <- hypotheses(h2b, hypothesis = "b1 = b4", type= "response")
h2b$term <- "H2b - balanced arguments and confirming cue"

## Plotting Difference in Probabilities Treatment conditions against control group - Data prep
cp <- rbind(h2b, h2a, h1b, h1a, conflicting_arg_cue, conflicting_arg, conflicting_cue)
cp

# Figure 1 manuscript ----------------------------------------------------------

fig1 <- ggplot(cp, aes(y = term, x = estimate, xmin = conf.low, xmax = conf.high)) +
  labs(x = "Difference in probabilities", y = "") +
  scale_y_discrete(
    limits = c(
      "H2b - balanced arguments and confirming cue", "H2a - balanced arguments and conflicting cue", 
      "H1b - conflicting arguments and confirming cue","H1a - confirming arguments and conflicting cue",
      "",  # Add an empty space between categories
      "Conflicting arguments and conflicting cue",
      "Conflicting cue and no arguments", 
      "Conflicting arguments and no cue")) + 
  geom_pointrange() +
  geom_vline(xintercept = 0, linetype = "dashed", color = "red") +
  theme_minimal() + 
  theme(
    axis.title.x = element_text(size = 20, face = "bold", color = "black"),
    axis.text = element_text(size = 20),
    axis.text.y = element_text(size = 20, face = "bold"),
    plot.caption = element_text(hjust = 0.5, color = "black", face = "italic", size = 16),
  ) +
  labs(caption = "0 = no difference between categories. 95% confidence intervals") +
  theme(
    plot.margin = margin(1, 1, 1, 1, "cm"),
    panel.spacing = unit(0.2, "lines"))

fig1

rm(conflicting_arg)
rm(conflicting_cue)
rm(conflicting_arg_cue)
rm(h1a)
rm(h1b)
rm(h2a)
rm(h2b)
rm(cp)
rm(fig1)

##### Difference in probabilities Fig.2 ----------------------------------------

# In hypothesis reference category is b1 (weak_partisan)
h1a_part_weak_strong <- predictions(mp, newdata = datagrid(aff_conf_arg = c("affirming arg","no arg"),
                                                           aff_conf_cue = c("conflicting cue","nothing"), 
                                                           party_strength_bin = c("weak_partisan", "strong_partisan")),type= "response")
h1a_part_weak_strong <- hypotheses(h1a_part_weak_strong, hypothesis = "b2 - b1 = 0 ", type= "response")
h1a_part_weak_strong$term <- "Confirming arguments and conflicting cue:\n\n partisans vs nonpartisans"

h1b_part_weak_strong <- predictions(mp, newdata = datagrid(aff_conf_arg = c("conflicting arg","no arg"),
                                                           aff_conf_cue = c("affirming cue","nothing"), 
                                                           party_strength_bin = c("weak_partisan", "strong_partisan")),type= "response")
h1b_part_weak_strong <- hypotheses(h1b_part_weak_strong, hypothesis = "b2 - b1 = 0 ", type= "response")
h1b_part_weak_strong$term <- "Conflicting arguments and confirming cue:\n\n partisans vs nonpartisans"

h2a_part_weak_strong <- predictions(mp, newdata = datagrid(aff_conf_arg = c("balanced arg","no arg"),
                                                           aff_conf_cue = c("conflicting cue","nothing"),
                                                           party_strength_bin = c("weak_partisan", "strong_partisan")),type= "response")
h2a_part_weak_strong <- hypotheses(h2a_part_weak_strong, hypothesis = "b2 - b1 = 0 ", type= "response")
h2a_part_weak_strong$term <- "Balanced arguments and conflicting cue:\n\n partisans vs nonpartisans"

h2b_part_weak_strong <- predictions(mp, newdata = datagrid(aff_conf_arg = c("balanced arg","no arg"),
                                                           aff_conf_cue = c("affirming cue","nothing"),
                                                           party_strength_bin = c("weak_partisan", "strong_partisan")) ,type= "response")
h2b_part_weak_strong <- hypotheses(h2b_part_weak_strong, hypothesis = "b2 - b1 = 0 ", type= "response")
h2b_part_weak_strong$term <- "Balanced arguments and confirming cue:\n\n partisans vs nonpartisans"


dp_mod_part<- rbind(h2b_part_weak_strong, h2a_part_weak_strong, h1b_part_weak_strong, h1a_part_weak_strong)
dp_mod_part

# Figure 2 Manuscript -------------------------------------------------------------
fig2 <- ggplot(dp_mod_part, aes(y = term, x = estimate, xmin = conf.low, xmax = conf.high)) +
  labs(x = "Difference in probabilities", y = "") +
  scale_y_discrete(
    limits = c(
      "Balanced arguments and confirming cue:\n\n partisans vs nonpartisans", "Balanced arguments and conflicting cue:\n\n partisans vs nonpartisans", 
      "Conflicting arguments and confirming cue:\n\n partisans vs nonpartisans","Confirming arguments and conflicting cue:\n\n partisans vs nonpartisans"
    )) + 
  geom_pointrange() +
  geom_vline(xintercept = 0, linetype = "dashed", color = "red") +
  theme_minimal() + 
  theme(
    axis.title.x = element_text(size = 20, face = "bold", color = "black"),
    axis.text = element_text(size = 20, face = "bold"),
    plot.caption = element_text(hjust = 0.5, color = "black", face = "italic", size = 16),
  ) +
  labs(caption = "0 = no difference between categories. 95% confidence intervals") +
  theme(
    plot.margin = margin(1, 1, 1, 1, "cm"),
    panel.spacing = unit(0.2, "lines")) 

fig2

rm(h1a_part_weak_strong)
rm(h1b_part_weak_strong)
rm(h2a_part_weak_strong)
rm(h2b_part_weak_strong)
rm(dp_mod_part)
rm(fig2)

###### Difference in probabilities Fig.3 ---------------------------------------

# In hypothesis reference category is b2 (high sophisticates)
h1a_soph_low_high <- predictions(msoph, newdata = datagrid(aff_conf_arg = c("affirming arg"),
                                                           aff_conf_cue = c("conflicting cue"),
                                                           soph_category = c("low soph", "high soph")), type = "response")
h1a_soph_low_high <- hypotheses(h1a_soph_low_high, hypothesis = "b1 - b2 = 0", type= "response")
h1a_soph_low_high$term <- "Confirming arguments and conflicting cue:\n\nlow vs high sophistication"

h1b_soph_low_high <- predictions(msoph, newdata = datagrid(aff_conf_arg = c("conflicting arg"),
                                                           aff_conf_cue = c("affirming cue"),
                                                           soph_category = c("low soph", "high soph")), type = "response")
h1b_soph_low_high <- hypotheses(h1b_soph_low_high, hypothesis = "b1 - b2 = 0", type= "response")
h1b_soph_low_high$term <- "Conflicting arguments and confirming cue:\n\nlow vs high sophistication"


h2a_soph_low_high <- predictions(msoph, newdata = datagrid(aff_conf_arg = c("balanced arg"),
                                                           aff_conf_cue = c("conflicting cue"),
                                                           soph_category = c("low soph", "high soph")), type = "response")
h2a_soph_low_high <- hypotheses(h2a_soph_low_high, hypothesis = "b1 - b2 = 0", type= "response")
h2a_soph_low_high$term <- "Balanced arguments and conflicting cue:\n\nlow vs high sophistication"


h2b_soph_low_high <- predictions(msoph, newdata = datagrid(aff_conf_arg = c("balanced arg"),
                                                           aff_conf_cue = c("affirming cue"),
                                                           soph_category = c("low soph", "high soph")), type = "response")
h2b_soph_low_high <- hypotheses(h2b_soph_low_high, hypothesis = "b1 - b2 = 0", type= "response")
h2b_soph_low_high$term <- "Balanced arguments and confirming cue:\n\nlow vs high sophistication"

msoph_mod_part<- rbind( h2b_soph_low_high, h2a_soph_low_high, h1b_soph_low_high, h1a_soph_low_high)
msoph_mod_part

# Figure 3 Manuscript ----------------------------------------------------------
fig3 <- ggplot(msoph_mod_part, aes(y = term, x = estimate, xmin = conf.low, xmax = conf.high)) +
  labs(x = "Difference in probabilities", y = "") +
  geom_pointrange() +
  geom_vline(xintercept = 0, linetype = "dashed", color = "red") +
  scale_y_discrete(
    limits = c(
      "Balanced arguments and confirming cue:\n\nlow vs high sophistication", "Balanced arguments and conflicting cue:\n\nlow vs high sophistication", 
      "Conflicting arguments and confirming cue:\n\nlow vs high sophistication", "Confirming arguments and conflicting cue:\n\nlow vs high sophistication"
    ))+
  theme_minimal() + 
  theme(
    axis.title.x = element_text(size = 20, face = "bold", color = "black"),
    axis.text = element_text(size = 20, face = "bold"),
    plot.caption = element_text(hjust = 0.5, color = "black", face = "italic", size = 16),
  ) +
  labs(caption = "0 = no difference between categories. 95% confidence intervals") +
  theme(
    plot.margin = margin(1, 1, 1, 1, "cm"),
    panel.spacing = unit(0.2, "lines")) 

fig3

rm(h1a_soph_low_high)
rm(h1b_soph_low_high)
rm(h2a_soph_low_high)
rm(h2b_soph_low_high)
rm(msoph_mod_part)
rm(fig3)
rm(msoph)

###### Difference in probabilities Fig.4----------------------------------------
# In hypothesis reference category is b1 (weak attitudes)

h1a_at_weak_strong<- predictions(mxs, newdata = datagrid(aff_conf_arg = c("affirming arg","no arg"),
                                                         aff_conf_cue = c("conflicting cue","nothing"), 
                                                         attitudes = c("weak", "strong")),type = "response")
h1a_at_weak_strong <- hypotheses(h1a_at_weak_strong, hypothesis = "b2 - b1 = 0", type= "response")
h1a_at_weak_strong$term <- "Confirming arguments and conflicting cue:\n\n strong vs weak attitudes"

h1b_at_weak_strong <- predictions(mxs, newdata = datagrid(aff_conf_arg = c("conflicting arg","no arg"),
                                                          aff_conf_cue = c("affirming cue","nothing"), 
                                                          attitudes = c("weak", "strong")) ,type = "response")
h1b_at_weak_strong <- hypotheses(h1b_at_weak_strong, hypothesis = "b2 - b1 = 0", type= "response")
h1b_at_weak_strong$term <- "Conflicting arguments and confirming cue:\n\n strong vs weak attitudes"

h2a_at_weak_strong <- predictions(mxs, newdata = datagrid(aff_conf_arg = c("balanced arg","no arg"),
                                                          aff_conf_cue = c("conflicting cue","nothing"),
                                                          attitudes = c("weak", "strong")), type = "response")
h2a_at_weak_strong <- hypotheses(h2a_at_weak_strong, hypothesis = "b2 - b1 = 0", type= "response")
h2a_at_weak_strong$term <- "Balanced arguments and conflicting cue:\n\n strong vs weak attitudes"

h2b_at_weak_strong <- predictions(mxs, newdata = datagrid(aff_conf_arg = c("balanced arg","no arg"),
                                                          aff_conf_cue = c("affirming cue","nothing"),
                                                          attitudes = c("weak", "strong")), type = "response")
h2b_at_weak_strong <- hypotheses(h2b_at_weak_strong, hypothesis = "b2 - b1 = 0", type= "response")
h2b_at_weak_strong$term <- "Balanced arguments and confirming cue:\n\n strong vs weak attitudes"

dp_mod_at<- rbind(h2b_at_weak_strong, h2a_at_weak_strong, h1b_at_weak_strong, h1a_at_weak_strong)
dp_mod_at

# Figure 4 Manuscript ----------------------------------------------------------
# Plot 
fig4 <- ggplot(dp_mod_at, aes(y = term, x = estimate, xmin = conf.low, xmax = conf.high)) +
  labs(x = "Difference in probabilities", y = "") +
  scale_y_discrete(
    limits = c(
      "Balanced arguments and confirming cue:\n\n strong vs weak attitudes", "Balanced arguments and conflicting cue:\n\n strong vs weak attitudes", 
      "Conflicting arguments and confirming cue:\n\n strong vs weak attitudes","Confirming arguments and conflicting cue:\n\n strong vs weak attitudes"
    )) + 
  geom_pointrange() +
  geom_vline(xintercept = 0, linetype = "dashed", color = "red") +
  theme_minimal() + 
  theme(
    axis.title.x = element_text(size = 20, face = "bold", color = "black"),
    axis.text = element_text(size = 20, face = "bold"),
    plot.caption = element_text(hjust = 0.5, color = "black", face = "italic", size = 16),
  ) +
  labs(caption = "0 = no difference between categories. 95% confidence intervals") +
  theme(
    plot.margin = margin(1, 1, 1, 1, "cm"),
    panel.spacing = unit(0.2, "lines")) 

fig4

rm(h1a_at_weak_strong)
rm(h1b_at_weak_strong)
rm(h2a_at_weak_strong)
rm(h2b_at_weak_strong)
rm(dp_mod_at)
rm(fig4)
rm(mxs)
########################################
####### Robustness tests--------------------------------------------------------
######## Difference in probabilities Fig.F1 -------------------------------------------

# Alternative baseline: policy information
# Reference category in hypothesis is b2 (policy info only)

h1a_alt <- predictions(mx, newdata = datagrid(aff_conf_arg = c("affirming arg","affirming arg"),
                                              aff_conf_cue = c("conflicting cue","nothing")), type= "response")
h1a_alt <- hypotheses(h1a_alt, hypothesis = "b1 - b2 = 0", type= "response")
h1a_alt$term <- "H1a - confirming arguments and conflicting cue vs confirming arguments"

h1b_alt <- predictions(mx, newdata = datagrid(aff_conf_arg = c("conflicting arg","conflicting arg"),
                                              aff_conf_cue = c("affirming cue","nothing")), type= "response")
h1b_alt <- hypotheses(h1b_alt, hypothesis = "b1 - b2 = 0", type= "response")
h1b_alt$term <- "H1b - conflicting arguments and confirming cue vs conflicting arguments"


h2a_alt <- predictions(mx, newdata = datagrid(aff_conf_arg = c("balanced arg","balanced arg"),
                                              aff_conf_cue = c("conflicting cue","nothing")), type= "response")
h2a_alt <- hypotheses(h2a_alt, hypothesis = "b1 - b2 = 0", type= "response")
h2a_alt$term <- "H2a - balanced arguments and conflicting cue vs balanced arguments"


h2b_alt <- predictions(mx, newdata = datagrid(aff_conf_arg = c("balanced arg","balanced arg"),
                                              aff_conf_cue = c("affirming cue","nothing")), type= "response")
h2b_alt <- hypotheses(h2b_alt, hypothesis = "b1 - b2 = 0", type= "response")
h2b_alt$term <- "H2b - balanced arguments and confirming cue vs balanced arguments"

rob_test_1<- rbind( h1a_alt, h1b_alt, h2a_alt, h2b_alt)
rob_test_1

# Figure F1 - Appendix F -------------------------------------------------------
Fig_f1 <- ggplot(rob_test_1, aes(y = term, x = estimate, xmin = conf.low, xmax = conf.high)) +
  labs(x = "Difference in probabilities", y = "") +
  scale_y_discrete(
    limits = c(
      "H2b - balanced arguments and confirming cue vs balanced arguments", "H2a - balanced arguments and conflicting cue vs balanced arguments", 
      "H1b - conflicting arguments and confirming cue vs conflicting arguments","H1a - confirming arguments and conflicting cue vs confirming arguments"
    )) + 
  geom_pointrange(size = 1.2, fatten = 2) +
  geom_vline(xintercept = 0, linetype = "dashed", color = "red") +
  theme_minimal() + 
  theme(
    axis.title.x = element_text(size = 12, face = "bold", color = "black"),
    axis.text = element_text(size = 12),
    axis.text.y = element_text(size = 12, face = "bold"),
    plot.caption = element_text(hjust = 0.5, color = "black", face = "italic", size = 12),
  ) +
  labs(caption = "0 = no difference between categories. 95% confidence intervals") +
  theme(
    plot.margin = margin(1, 1, 1, 1, "cm"),
    panel.spacing = unit(0.2, "lines"))

Fig_f1

rm(h1a_alt)
rm(h1b_alt)
rm(h2a_alt)
rm(h2b_alt)
rm(rob_test_1)
rm(Fig_f1)

######### Difference in probabilities Fig.F2 ------------------------------------------
# Robustness test - replication main analysis with restricted sample size 

# Identify respondents to filter out : Respondents who got PID assigned baed on Q2 
df_alt <- df %>%
  mutate(
    filter_pid = case_when(
      ( pid_close_w1 %in% c("no", "dk") &  pid_remind_w1 %in% c("no", "dk")) |
        ( pid_first_w1 %in% c("dk", "Other") | is.na(pid_first_w1)) & 
        ( pid_remind_first_w1 %in% c("dk", "Other") | is.na(pid_remind_first_w1) ) ~ 1,
      TRUE ~ 0))

# Remove respondents to whom we assign a party
df_alt <- df_alt %>% filter(filter_pid != 1) %>% droplevels()

# We remove 363 observations. We are thus left with N = 2263

# Replicate model
mx_alt <- glm(vote_prepost_rcd_bin ~ aff_conf_arg * aff_conf_cue, data = df_alt, family = binomial(link = "logit"))
summary(mx_alt)

# Difference in probabilities 
# Reference category in hypothesis is b4 (no arg nothing)

#  Replication H1a
h1a <- predictions(mx_alt, newdata = datagrid(aff_conf_arg = c("affirming arg","no arg"),
                                              aff_conf_cue = c("conflicting cue","nothing")),type= "response")
h1a <- hypotheses(h1a, hypothesis = "b1 = b4", type= "response")
h1a$term <- "H1a - confirming arguments and conflicting cue"

# Replication H1b
h1b <- predictions(mx_alt, newdata = datagrid(aff_conf_arg = c("conflicting arg","no arg"),
                                              aff_conf_cue = c("affirming cue","nothing")), type = "response")
h1b <- hypotheses(h1b, hypothesis = "b1 = b4", type= "response")
h1b$term <- "H1b - conflicting arguments and confirming cue"

# Replication H2a
h2a <- predictions(mx_alt, newdata = datagrid(aff_conf_arg = c("balanced arg","no arg"),
                                              aff_conf_cue = c("conflicting cue","nothing")), type = "response")
h2a <- hypotheses(h2a, hypothesis = "b1 = b4", type= "response")
h2a$term <- "H2a - balanced arguments and conflicting cue"

# Replication H2b
h2b <- predictions(mx_alt, newdata = datagrid(aff_conf_arg = c("balanced arg","no arg"),
                                              aff_conf_cue = c("affirming cue","nothing")), type = "response")
h2b <- hypotheses(h2b, hypothesis = "b1 = b4", type= "response")
h2b$term <- "H2b - balanced arguments and confirming cue"

## Plotting Difference in Probabilities Treatment conditions against control group - Data prep
cp_alt <- rbind(h2b, h2a, h1b, h1a)
cp_alt

# Figure F2 - Appendix F ------------------------------------------------------- 
Fig_f2 <- ggplot(cp_alt, aes(y = term, x = estimate, xmin = conf.low, xmax = conf.high)) +
  labs(x = "Difference in probabilities", y = "") +
  scale_y_discrete(
    limits = c(
      "H2b - balanced arguments and confirming cue", "H2a - balanced arguments and conflicting cue", 
      "H1b - conflicting arguments and confirming cue","H1a - confirming arguments and conflicting cue")) + 
  geom_pointrange(size = 1.2, fatten = 2) +
  geom_vline(xintercept = 0, linetype = "dashed", color = "red") +
  theme_minimal() + 
  theme(
    axis.title.x = element_text(size = 16, face = "bold", color = "black"),
    axis.text = element_text(size = 16),
    axis.text.y = element_text(size = 14, face = "bold"),
    plot.caption = element_text(hjust = 0.5, color = "black", face = "italic", size = 12),
  ) +
  labs(caption = "0 = no difference between categories. 95% confidence intervals") +
  theme(
    plot.margin = margin(1, 1, 1, 1, "cm"),
    panel.spacing = unit(0.2, "lines"))

Fig_f2

rm(h1a)
rm(h1b)
rm(h2a)
rm(h2b)
rm(cp_alt)
rm(Fig_f2)
rm(mx_alt)
rm(df_alt)

########## Difference in probabilities Figure F3 --------------------------------
# Robustness test - Restrictive measure of partisanship "ANES" style. 

df$p_strength_anes <- fct_collapse(df$party_strength, weak_partisan = c("0", "1"),
                                   strong_partisan = c("2"))

mp_anes <- glm(vote_prepost_rcd_bin ~ aff_conf_arg*aff_conf_cue*p_strength_anes, data = df, family = binomial(link = "logit"))
summary(mp_anes)

# Difference in probabilities 
# Reference category for hypothesis is b1 (weak partisans)

h1a_part_weak_strong <- predictions(mp_anes,
                                    newdata = datagrid(aff_conf_arg = c("affirming arg","no arg"),
                                                       aff_conf_cue = c("conflicting cue","nothing"), 
                                                       p_strength_anes = c("weak_partisan", "strong_partisan")), type = "response")
h1a_part_weak_strong <- hypotheses(h1a_part_weak_strong, hypothesis = "b2 - b1 = 0", type= "response")
h1a_part_weak_strong$term <- "Confirming arguments and conflicting cue:\n\n partisans vs nonpartisans"


h1b_part_weak_strong <- predictions(mp_anes, newdata = datagrid(aff_conf_arg = c("conflicting arg","no arg"),
                                                                aff_conf_cue = c("affirming cue","nothing"), 
                                                                p_strength_anes = c("weak_partisan", "strong_partisan")),type= "response")
h1b_part_weak_strong <- hypotheses(h1b_part_weak_strong, hypothesis = "b2 - b1 = 0", type= "response")
h1b_part_weak_strong$term <- "Conflicting arguments and confirming cue:\n\n partisans vs nonpartisans"

h2a_part_weak_strong <- predictions(mp_anes, newdata = datagrid(aff_conf_arg = c("balanced arg","no arg"),
                                                                aff_conf_cue = c("conflicting cue","nothing"),
                                                                p_strength_anes = c("weak_partisan", "strong_partisan")), type= "response")
h2a_part_weak_strong <- hypotheses(h2a_part_weak_strong, hypothesis = "b2 - b1 = 0", type= "response")
h2a_part_weak_strong$term <- "Balanced arguments and conflicting cue:\n\n partisans vs nonpartisans"

h2b_part_weak_strong <- predictions(mp_anes, newdata = datagrid(aff_conf_arg = c("balanced arg","no arg"),
                                                                aff_conf_cue = c("affirming cue","nothing"),
                                                                p_strength_anes = c("weak_partisan", "strong_partisan")), type= "response")
h2b_part_weak_strong <- hypotheses(h2b_part_weak_strong, hypothesis = "b2 - b1 = 0", type= "response")
h2b_part_weak_strong$term <- "Balanced arguments and confirming cue:\n\n partisans vs nonpartisans"

dp_mod_p_anes<- rbind(h2b_part_weak_strong, h2a_part_weak_strong, h1b_part_weak_strong, h1a_part_weak_strong  )
dp_mod_p_anes

# Figure F3 Appendix F----------------------------------------------------------
Fig_f3 <- ggplot(dp_mod_p_anes, aes(y = term, x = estimate, xmin = conf.low, xmax = conf.high)) +
  labs(x = "Difference in probabilities", y = "") +
  scale_y_discrete(
    limits = c(
      "Balanced arguments and confirming cue:\n\n partisans vs nonpartisans", "Balanced arguments and conflicting cue:\n\n partisans vs nonpartisans", 
      "Conflicting arguments and confirming cue:\n\n partisans vs nonpartisans","Confirming arguments and conflicting cue:\n\n partisans vs nonpartisans"
    )) + 
  geom_pointrange(size = 1.2, fatten = 2) +
  geom_vline(xintercept = 0, linetype = "dashed", color = "red") +
  theme_minimal() + 
  theme(
    axis.title.x = element_text(size = 16, face = "bold", color = "black"),
    axis.text = element_text(size = 16, face = "bold"),
    plot.caption = element_text(hjust = 0.5, color = "black", face = "italic", size = 14),
  ) +
  labs(caption = "0 = no difference between categories. 95% confidence intervals") +
  theme(
    plot.margin = margin(1, 1, 1, 1, "cm"),
    panel.spacing = unit(0.1, "lines")) 

Fig_f3

rm(h1a_part_weak_strong)
rm(h1b_part_weak_strong)
rm(h2a_part_weak_strong)
rm(h2b_part_weak_strong)
rm(dp_mod_p_anes)
rm(Fig_f3)
rm(mp_anes)

########################################
############ Supplementary material --------------------------------------------

# Table D1 - Appendix D --------------------------------------------------------
#### Difference in means vote intention-----------------------------------------
newt <- df
# Vote intention numeric 
newt <- newt %>%
  mutate(
    exp_vint_n = case_when(
      exp_vint == "certainly favor" ~ 4,
      exp_vint == "likely favor" ~ 3,
      exp_vint == "likely against" ~ 2,
      exp_vint == "certainly against" ~ 1,
      exp_vint == "dk" ~ NA_real_,
      TRUE ~ NA_real_  ))

# Re-group treatments 
newt <- newt %>% 
  mutate(experiment_groups = case_when(
    exp_arg == "no arg" & exp_party_reco_rcd == "nothing" ~ "control",
    exp_arg == "no arg" & exp_party_reco_rcd == "no" ~ "abs arg contra cue",
    exp_arg == "no arg" & exp_party_reco_rcd == "yes" ~ "abs arg pro cue",
    exp_arg == "contra" & exp_party_reco_rcd == "nothing" ~ "contra arg abs cue",
    exp_arg == "contra" & exp_party_reco_rcd == "no" ~ "contra arg contra cue",
    exp_arg == "contra" & exp_party_reco_rcd == "yes" ~ "contra arg pro cue",
    exp_arg == "pro" & exp_party_reco_rcd == "nothing" ~ "pro arg abs cue",
    exp_arg == "pro" & exp_party_reco_rcd == "no" ~ "pro arg contra cue",
    exp_arg == "pro" & exp_party_reco_rcd == "yes" ~ "pro arg pro cue",
    exp_arg == "mixed" & exp_party_reco_rcd == "nothing" ~ "mixed arg abs cue",
    exp_arg == "mixed" & exp_party_reco_rcd == "no" ~ "mixed arg contra cue",
    exp_arg == "mixed" & exp_party_reco_rcd == "yes" ~ "mixed arg pro cue",
    
    TRUE ~ NA))

newt$experiment_groups <- as.factor(newt$experiment_groups)
newt$experiment_groups <- relevel(newt$experiment_groups, ref = "control") 

# Create data frame to store results
ttest_vote_intention <- data.frame(
  treatment = unique(newt$experiment_groups),
  mean_support = NA,
  sd_support = NA,
  n = NA,
  p_value = NA
)

# Filter control group data
control_data <- newt %>% filter(experiment_groups == "control")

# Perform t-tests for each treatment group
for (group in unique(newt$experiment_groups)) {
  treatment_df <- newt %>% filter(experiment_groups == group)
  
  # Skip the control group
  if (group == "control") {
    ttest_vote_intention[ttest_vote_intention$treatment == group, c("mean_support", "sd_support", "n")] <- 
      c(
        mean(control_data$exp_vint_n, na.rm = TRUE), 
        sd(control_data$exp_vint_n, na.rm = TRUE), 
        nrow(control_data)
      )
    next
  }
  
  # Perform the t-test
  test <- t.test(
    treatment_df$exp_vint_n, control_data$exp_vint_n, 
    alternative = "two.sided", var.equal = FALSE
  )
  
  # Store results
  ttest_vote_intention[ttest_vote_intention$treatment == group, ] <- list(
    group,
    mean(treatment_df$exp_vint_n, na.rm = TRUE),
    sd(treatment_df$exp_vint_n, na.rm = TRUE), 
    nrow(treatment_df),
    test$p.value
  )
}


rm(ttest_vote_intention)
rm(control_data)
rm(treatment_df)
rm(test)
rm(newt)

# Table D2 - Appendix D --------------------------------------------------------
# Cross tab between the two main factors and the dependent variable direction of the change 

library(questionr)      
library(vcd)            

## Recode vote change (2 categories)
df$vote_prepost_rcd <- fct_collapse(df$vote_prepost, stability = c("against -> against", "favor -> favor"),
                                    change_to_yes = c("against -> favor"),
                                    change_to_no = c("favor -> against"))

# Party Cue vote change
tab <- xtabs(~ vote_prepost_rcd + exp_arg, data = df, subset = NULL)
cprop(tab)
# Argument vote change
tab2 <- xtabs(~ vote_prepost_rcd + exp_party_reco_rcd, data = df, subset = NULL)
cprop(tab2)

rm(tab)
rm(tab2)
rm(m)
rm(mx)
rm(mp)
rm(df)
